package com.shzu.jwc.ty.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shzu.jwc.ty.bean.JudgeProblem;
import com.shzu.jwc.ty.bean.JudgeProblemExample;
import com.shzu.jwc.ty.dao.JudgeProblemMapper;

@Service
public class JudgeProblemservice {

	@Autowired
	JudgeProblemMapper judgeProblemMapper;
	
	public List<JudgeProblem> getjugeproblem()
	{
		return judgeProblemMapper.selectByExample(null);
	}
	
	
	public List<JudgeProblem> getsearchjugeproblem(Integer problemClassId)
	{
		JudgeProblemExample example=new JudgeProblemExample();
		JudgeProblemExample.Criteria criteria=example.createCriteria();
		criteria.andProblemClassIdEqualTo(problemClassId);
		return judgeProblemMapper.selectByExample(example);
		
	}
	
	public Integer insertjudge(JudgeProblem judgeProblem)
	{
		JudgeProblemExample example=new JudgeProblemExample();
		JudgeProblemExample.Criteria criteria=example.createCriteria();
		criteria.andJudgeProblemTitleEqualTo(judgeProblem.getJudgeProblemTitle());
		if(judgeProblemMapper.countByExample(example)>0)
			return 1;
		else
			return judgeProblemMapper.insert(judgeProblem);
		
	}
	
	public Integer deletejudge(Integer judgeProblemId)
	{
		return judgeProblemMapper.deleteByPrimaryKey(judgeProblemId);
	}
	
	public Integer updatejudge(Integer id,String column,String value)
	{
		JudgeProblem judgeProblem=judgeProblemMapper.selectByPrimaryKey(id);
		if(column.equals("judgeProblemTitle"))
			judgeProblem.setJudgeProblemTitle(value);
		if(column.equals("judgeProblemRight"))
			judgeProblem.setJudgeProblemRight(Integer.parseInt(value));
		if(column.equals("problemClassId"))
			judgeProblem.setProblemClassId(Integer.parseInt(value));
		return judgeProblemMapper.updateByPrimaryKey(judgeProblem);
	}
}
